MAKE                =	make
CC                  =	g++
INCPATH             =   ../include
LIB_DIR             =   ../lib/linux/
BIN_DIR             =   ../bin/linux/
GTLOG_LIB_DIR       =   ../tools/gtlog/lib/Linux/
GTLOG_INCLUDE_DIR   =   ../tools/gtlog/include/
LOG_LIB_DIR         =   ../tools/log/lib/linux/
LOG_INCLUDE_DIR     =   ../tools/log/include/
EXE                 =   cppTutor
STATIC_TEST         =   libcppTutor.a
SHARED_TEST         =   libcppTutor.so
STATIC_LOG          =   lcppTutorLog
GTLOG               =   lgtlog
CPPOX               =   -std=c++0x
#LINK                =	-g -pedantic -Wall -lstdc++ -lpthread -ldl -lm -$(STATIC_LOG) -Wl,-rpath,.
#LINK                =	-g -pedantic -Wall -lstdc++ -lpthread -ldl -lm -$(STATIC_LOG) -$(GTLOG) -Wl,-rpath,.
LINK                =	-g -pedantic -Wall -lstdc++ -lpthread -ldl -lm -Wl,-rpath,.
COMPILE	            =	-g -O0 $(CPPOX) -D_THREAD_SAFE -Wextra -pedantic -Wall -c -fPIC -Wno-deprecated 
SRCS                =   $(shell ls *.cpp)
SRCS_C              =   $(shell ls *.c)
OBJS                =   $(subst .cpp,.o,$(SRCS))
OBJS_C              =   $(subst .c,.o,$(SRCS_C))

# socket libraries
CLIENT_LIB_STA	=   libcppTutorTCPClient.a
CLIENT_LIB_DYA  =   libcppTutorTCPClient.so
SERVER_LIB_STA	=   libcppTutorTCPServer.a
SERVER_LIB_DYA  =   libcppTutorTCPServer.so

.SUFFIXES: .o .cpp .c

.cpp.o:
#	$(CC) -I $(INCPATH) -I $(LOG_INCLUDE_DIR) -I $(GTLOG_INCLUDE_DIR) $(COMPILE) $<
	$(CC) -I $(INCPATH) $(COMPILE) $<

.c.o:
	$(CC) -I $(INCPATH) $(COMPILE) $<

all: $(OBJS) $(OBJS_C)
	$(CC) -o $(BIN_DIR)$(EXE) $(OBJS) $(OBJS_C) -L. $(LINK) 
#	$(CC) -o $(BIN_DIR)$(EXE) $(OBJS) $(OBJS_C) -L $(LOG_LIB_DIR) -L $(GTLOG_LIB_DIR) -L. $(LINK) 
#	$(CC) -o $(BIN_DIR)$(EXE) $(OBJS) $(OBJS_C) -L $(LOG_LIB_DIR) -L. $(LINK) 	
#	$(CC) -o $(BIN_DIR)$(EXE) $(OBJS) $(OBJS_C) -L. $(LINK) -L$(LIB_DIR)$(CLIENT_LIB_STA) -L$(LIB_DIR)$(SERVER_LIB_STA)

-include depend.mak

depend:
	g++ -MM $(SRCS) > depend.mak

shared: $(OBJS)
	$(CC) -shared -Wl,-soname -lc -o $(LIB_DIR)$(SHARED_TEST) $(OBJS) -L.

static: $(OBJS)
	ar rucvs $(LIB_DIR)$(STATIC_TEST) $(OBJS)

clean:
	rm -rf $(OBJS) $(OBJS_C) depend.mak $(BIN_DIR)$(EXE) $(LIB_DIR)*

cleanapp:
	rm -rf $(BIN_DIR)$(EXE) $(LIB_DIR)

distclean:
	rm -rf $(OBJS) $(OBJS_C) depend.mak $(BIN_DIR)$(EXE) $(LIB_DIR)*

